//
//  TPWalletManager.m
//  TradingPlatform
//
//  Created by 李坤 on 2019/5/16.
//  Copyright © 2019 程强. All rights reserved.
//

#import "TPWalletManager.h"
#import "TPWalletAccountObj.h"
#import "NSString+YYAdd.h"
#import "YYModel.h"

@implementation TPWalletManager
- (DSASubject *)getMyWalletAccountInfo:(NSString *)uid withType:(NSString *)type
{
    DSASubject *subject = [DSASubject subject];
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:uid,@"user_id",nil];
    if ([type isEqualToString:@"1"]) {
        dic = [NSDictionary dictionaryWithObjectsAndKeys:uid,@"user_id",type,@"type",nil];
    }
    NSString *doVerifyurl=[NSString stringWithFormat:@"%@/index.php?mod=orderdata&act=bank", WalletServerURL];
    [KKHttpServices httpPostUrl:doVerifyurl prams:dic success:^(id responseObject, KKHttpParse *parse) {
        NSDictionary *dic = parse.responseJsonOB;
        TPWalletAccountObj *account = [TPWalletAccountObj yy_modelWithDictionary:dic[@"obj"]];
        [subject sendNext:account];
        [subject sendCompleted];
    } failure:^(KKHttpParse *parse) {
        NSError *error = nil;
        [KKHttpServices creatHttpErr:parse err:&error];
        [subject sendError:error];
        [subject sendCompleted];
    }];
    return subject;
}
- (DSASubject *)getMyWalletBalance:(NSString *)uid withType:(NSString *)type
{
    DSASubject *subject = [DSASubject subject];
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:uid,@"user_id",nil];
    if ([type isEqualToString:@"1"]) {
        dic = [NSDictionary dictionaryWithObjectsAndKeys:uid,@"user_id",type,@"type",nil];
    }
    NSString *doVerifyurl=[NSString stringWithFormat:@"%@/index.php?mod=orderdata&act=wallet", WalletServerURL];
    [KKHttpServices httpPostUrl:doVerifyurl prams:dic success:^(id responseObject, KKHttpParse *parse) {
        NSDictionary *dic = parse.responseJsonOB;
        NSString *wallet = ValidString(dic[@"obj"]);
        [subject sendNext:wallet];
        [subject sendCompleted];
    } failure:^(KKHttpParse *parse) {
        NSError *error = nil;
        [KKHttpServices creatHttpErr:parse err:&error];
        [subject sendError:error];
        [subject sendCompleted];
    }];
    return subject;
}
- (DSASubject *)onekeyAccountOpening:(NSString *)uid withType:(NSString *)type
{
    DSASubject *subject = [DSASubject subject];
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:uid,@"user_id",nil];
    if ([type isEqualToString:@"1"]) {
        dic = [NSDictionary dictionaryWithObjectsAndKeys:uid,@"user_id",type,@"type",nil];
    }
    NSString *doVerifyurl=[NSString stringWithFormat:@"%@/index.php?mod=orderdata&act=onekey", WalletServerURL];
    [KKHttpServices httpPostUrl:doVerifyurl prams:dic success:^(id responseObject, KKHttpParse *parse) {
        NSDictionary *dic = parse.responseJsonOB;
        NSString *wallet = ValidString(dic[@"obj"]);
        [subject sendNext:wallet];
        [subject sendCompleted];
    } failure:^(KKHttpParse *parse) {
        NSError *error = nil;
        [KKHttpServices creatHttpErr:parse err:&error];
        [subject sendError:error];
        [subject sendCompleted];
    }];
    return subject;
}
- (DSASubject *)orderPayWithOrderID:(NSString *)oid
{
    DSASubject *subject = [DSASubject subject];
    MyUser;
    NSString *key = [NSString stringWithFormat:@"%@%@",@"DECXiuyujkUJUSUF836344SISO9871",user.userid];
    key = [key md5String];
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:oid,@"order_id",key,@"sgin",nil];
    NSString *doVerifyurl=[NSString stringWithFormat:@"%@/index.php?mod=orderdata&act=orderpay", WalletServerURL];
    [KKHttpServices httpPostUrl:doVerifyurl prams:dic success:^(id responseObject, KKHttpParse *parse) {
        NSDictionary *dic = parse.responseJsonOB;
        NSString *wallet = ValidString(dic[@"obj"]);
        [subject sendNext:wallet];
        [subject sendCompleted];
    } failure:^(KKHttpParse *parse) {
        NSError *error = nil;
        [KKHttpServices creatHttpErr:parse err:&error];
        [subject sendError:error];
        [subject sendCompleted];
    }];
    return subject;
}
@end
